#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFile>
#include <QThread>
#include <QTableWidget>
#include <QPushButton>
#include <QComboBox>
#include <QMap>

#include "worker.h"
#include "ControlCAN.h"
#include "canthread.h"



QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    void loadStyleSheet(const QString &filePath);

    void AddDataToList(QStringList strList);


    ~MainWindow();


private slots:

    void onGetProtocolData(VCI_CAN_OBJ *vci,unsigned int dwRel,unsigned int channel);

    void onBoardInfo(VCI_BOARD_INFO vbi);

    void on_pbtn_opencan_clicked(); //打开设备

    void on_pbtn_sendmsg_clicked();

    void on_pbtn_clearTrace_clicked();

    void on_pbtn_resetcan_clicked();//复位设备

    void on_pbtn_initcan_clicked();//初始化设备

    void on_pbtn_startcan_clicked();//启动设备


    void deviceOpensucced(bool state);

    void deviceCloseSucceed(bool state);

    void deviceInitSucceed();

    void deviceResetSucceed();

    void deviceStartSucceed();

    void deviceSendDataSucced();

    void debugmsg();
    void on_tableWidget_sectionClicked(int logicalIndex);
    void on_sortByID_clicked();
signals:
    bool RequestoOpendevice(UINT deviceType,UINT debicIndex,UINT baundRate);


    bool RequesttoClosedevice();

    bool RequesttoInitdevice();

    bool RequesttoResetDevice();

    bool RequesttoStartDevice();

    void RequesttoSendData(UINT channel,UINT ID,BYTE remoteFlag,BYTE externFlag,const unsigned char *data,BYTE len);


private:
    Ui::MainWindow *ui;
    QThread *canThread;
    CANThread *canWorker; // 工作线程

    QTabWidget *tabWidget;
    QWidget *targetPage_cfg;
    QWidget *cfgpage_canset;
    QComboBox *msgsendchannel;
    QComboBox *canIDType;
    QComboBox *candatatype;
    QComboBox *combox_buardrate_channel1;
    QComboBox *combox_buardrate_channel2;
    QComboBox *canchannel1inhibsts;
    QComboBox *canchannel2inhibsts;
    QComboBox *cantraceDisplaysorType;
    QLineEdit *send_candata ;
    QLineEdit *send_canid ;
    QPushButton *button_opencan;
    QPushButton *button_initcan;
    QPushButton *button_resetcan;
    QPushButton *button_startcan;
    QPushButton *button_sendmsg;
    QPushButton *button_cleartrace;
    QPushButton *button_clearsendmsg;
    QTableWidget *tablewidget_trace ;


    QMap<QString, int> idToRowMap; // 用于存储 CAN ID 到行号的映射

};
#endif // MAINWINDOW_H
